//import kotlinx.cinterop.*
//import com.huawei.ffrt.*
//import kotlin.experimental.ExperimentalNativeApi
//
//@OptIn(ExperimentalForeignApi::class)
//private fun extractClosurePtr(arg: COpaquePointer?): COpaquePointer {
//    requireNotNull(arg)
//    val headerSize = sizeOf<ffrt_function_header_t>()
//    val closureOffset = arg.rawValue + headerSize
//    return closureOffset.toLong().toCPointer<COpaquePointerVar>()!!.pointed.value!!
//}
//
//@OptIn(ExperimentalForeignApi::class)
//fun createFunctionWrapper(
//    func: () -> Unit,
//    kind: ffrt_function_kind_t
//): CPointer<ffrt_function_header_t> {
//    val stableRef = StableRef.create(func)
//    val functionStorage = ffrt_alloc_auto_managed_function_storage_base(kind)
//        ?: throw Error("Failed to allocate function storage")
//
//    /*
//        functionStorage:
//        +-----------------------------+ <-- arg
//        | ffrt_function_header_t      | <-- header fields (exec, destroy, ...)
//        |   exec = execFunction       |
//        |   destroy = destroyFunction |
//        |   reserve[2] = 0            |
//        +-----------------------------+
//        | StableRef<() -> Unit>       | <-- closure ptr (offset = sizeof(header))
//        +-----------------------------+
//    */
//    val header = functionStorage.reinterpret<ffrt_function_header_t>()
//    header.pointed.exec = staticCFunction { arg ->
//        extractClosurePtr(arg).asStableRef<() -> Unit>().get().invoke()
//    }
//    header.pointed.destroy = staticCFunction { arg ->
//        extractClosurePtr(arg).asStableRef<() -> Unit>().dispose()
//    }
//    header.pointed.reserve[0] = 0uL
//    header.pointed.reserve[1] = 0uL
//
//    // 将 StableRef 存储在 header 后面，用于 C++ 风格封装
//    val headerSize = sizeOf<ffrt_function_header_t>()
//    val closureStorageOffset = functionStorage.rawValue + headerSize
//    closureStorageOffset.toLong().toCPointer<ULongVar>()?.pointed?.value =
//        stableRef.asCPointer().rawValue.toLong().toULong()
//
//    return header
//}
//
//@OptIn(ExperimentalForeignApi::class)
//object Task {
//    // 封装 ffrt_submit_base
//    fun submit(
//        func: () -> Unit
//    ) {
//        val funcWrapper = createFunctionWrapper(func, ffrt_function_kind_t.ffrt_function_kind_general)
//        ffrt_submit_base(funcWrapper, null, null, null)
//    }
//
//    // 封装 ffrt_wait
//
//    fun wait() {
//        ffrt_wait()
//    }
//}